package com.zhushou;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;

import com.testdb.R;
import com.zhushou.util.BaodianDataUitl;
import com.zhushou.util.MianShiDataUitl;

public class MainActivity extends Activity {
    int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // androidBaoDian();
        mianshiBaodian();

    }



    /**
     * 面试宝典数据解析
     */
    private void mianshiBaodian() {


        Cursor cursor = AppApplication.getInstance().db1.rawQuery("Select * from Interview", null);
        id = 0;
        while (cursor.moveToNext()) {
            int QuestionIndex = cursor.getColumnIndex("Question");// 问题
            int AnswerIndex = cursor.getColumnIndex("Answer");// 回答
            if (AnswerIndex > -1) {
                String Question = cursor.getString(QuestionIndex);
                String Answer = cursor.getString(AnswerIndex);
                MianShiDataUitl.createData(MainActivity.this, Question, Answer);

            }
        }
        cursor.close();

    }

    /**
     * 安卓宝典数据解析
     */
    private void androidBaoDian() {
        Cursor cursor = AppApplication.getInstance().db1.rawQuery("Select * from P试题", null);
        id = 0;
        while (cursor.moveToNext()) {
            int shitiIndex = cursor.getColumnIndex("P试题ID");
            int tiXingIndex = cursor.getColumnIndex("P题型ID");
            int timuIndex = cursor.getColumnIndex("题目");
            int xuanxiangIndex = cursor.getColumnIndex("选项");
            int daanIndex = cursor.getColumnIndex("答案");
            if (timuIndex > -1) {
                String tiType = cursor.getString(tiXingIndex);// 题目类型
                if (tiType.equals("1")) {// 单项选择题
                    String name = cursor.getString(timuIndex);// 查询出所有的题目名称
                    String byjhmc = cursor.getString(xuanxiangIndex);// 选项内容
                    String shitiids = cursor.getString(shitiIndex);// 试题id
                    String daan = cursor.getString(daanIndex);// 正确答案
                    String[] s = (byjhmc.trim()).split("#");// 分割得到
                    Log.d("==读取数据==", "" + s.length);

                    BaodianDataUitl.createTest(MainActivity.this, s, "" + id, name, daan, 1);
                    id++;

                } else if (tiType.equals("2")) {// 多项选择题
                }

            }
        }
        cursor.close();
    }
}
